#include "crossbit/UTIL.h"

#include <stdio.h>
#include <string.h>
#include <stdarg.h>

using namespace crossbit;

void UTIL::XTLOG(const XTPStr str, ...){
				XTPStr cur = str;
				va_list list;
				va_start(list,str);
				while( *cur ){
								if( *cur == '%' ){
												switch( *(++cur) ){
																case 'd' : printf("%d" , va_arg( list , XTInt32  ) );
																					 break;
																case 's' : printf( "%s" , va_arg( list , XTPStr ));           
																					 break;
																case 'x' : printf("%x" , va_arg( list , XTInt32 ) );
																					 break;
																case 'u' : printf("%u" , va_arg( list , XTInt32 ) );
																					 break;
																default  : printf( "un support format\n"  );
																					 return ;

												}
												cur++;

								}else
												printf("%c" , *cur++ );
				}
}

XTUint32 UTIL::XTStrlen( const XTPStr str){
				return strlen( str );
}

void UTIL::XTStrcpy( XTPStr to , const XTPStr from ){
				strcpy( to , from );
}

XTPStr XTStrcat( XTPStr dest , const XTPStr src )
{
			return strcat( dest, src );
}

void UTIL::XTMemcpy( void* to , const void* from , XTUint32 size ){
				memcpy( to , from , size );
};

void* UTIL::XTMemset( void* s, XTInt32 c, XTUint32 size ){
				return memset( s , c , size );
};

void* UTIL::XTMalloc( XTUint32 size ){
				return malloc( size );
};

void UTIL::XTFree( void* addr ){
				free( addr );
};

